﻿using System;

namespace Core
{
    public struct Range : IEquatable<Range>
    {
        public int Min;
        public int Max;

        public Range(int min, int max)
        {
            Min = min;
            Max = max;
        }

        public static Range New(int min, int max)
        {
            return new Range(min, max);
        }

        public readonly bool Within(int v)
        {
            return v >= Min && v <= Max;
        }

        public bool Equals(Range other) => Min == other.Min && Max == other.Max;

        public override bool Equals(object obj)
        {
            if (obj == null || (obj is Range) == false)
            {
                return false;
            }
            return Equals((Range)obj);
        }

        public override int GetHashCode()
        {
            return Min.GetHashCode() ^ (Max.GetHashCode() << 2);
        }

        public override string ToString()
        {
            return $"({Min},{Max})";
        }
    }
}
